//    Copyright (C) Kherty.  All rights reserved.
#region

using System.Collections.Generic;
using OpenLS.Core.Serialization;

#endregion

namespace OpenLS.Vml
{
    internal abstract class ShapeBase : IOfficeXmlSerializable
    {
        private readonly AllCoreAttributes AllCoreAttributes = new AllCoreAttributes();
        private readonly AllShapeAttributes AllShapeAttributes = new AllShapeAttributes();
        private readonly List<ShapeElement> elements = new List<ShapeElement>();

        #region IOfficeXmlSerializable Members

        public abstract void ReadXml(ReadContext context);

        public abstract void WriteXml(WriteContext context);

        #endregion

        internal void ReadXmlContent(ReadContext context
            )
        {
            ReadShapeAttributes(context);
            elements.Clear();
            elements.AddRange(ReadHelper.ReadMany(() => ShapeElement.ReadShapeElement(context)));
        }

        internal void ReadShapeAttributes(ReadContext context)
        {
            AllCoreAttributes.ReadXml(context);
            AllShapeAttributes.ReadXml(context);
        }

        internal void WriteXmlContent(WriteContext c)
        {
            WriteShapeAttributes(c);
            c.WriteElements(elements);
        }

        internal void WriteShapeAttributes(WriteContext c)
        {
            AllCoreAttributes.WriteXml(c);
            AllShapeAttributes.WriteXml(c);
        }
    }
}